#include "NumberValidator.h"
#include "NullPointerException.h"

NumberValidator::NumberValidator(const QString& field,int minimum, int maximum, bool mandatory)
{
	this->mandatory = mandatory;
	this->min = minimum;
	this->max = maximum;
	this->field = field;
}

NumberValidator::~NumberValidator(void)
{
}

void NumberValidator::setMandatory(bool m)
{
	this->mandatory = m;
}
int NumberValidator::validate(QString& input)
{
	if(this->mandatory && input.isEmpty())
	{
		this->message = this->field + " is mandatory";
		return -1;
	}

	bool ok = false;
	int filenr = input.toInt(&ok);
	if(!ok)
	{
		this->message = this->field + " must be a positive number";
		return -2;
	}
	if(filenr<0 || filenr > 9999999999)
	{
		this->message = this->field + " must be a positive number";
		return -2;
	}
	return 0;
}